from django.shortcuts import render
from rest_framework.generics import CreateAPIView
from rest_framework.viewsets import ReadOnlyModelViewSet
from rest_framework_extensions.cache.mixins import CacheResponseMixin

from .models import Area
from . import serializers


class AreaInfoView(CreateAPIView, ReadOnlyModelViewSet):

    # serializer_class = serializers.AreaInfoSerializer
    # queryset = Area.objects.filter(parent=None)
    pagination_class = None

    def get_serializer_class(self):
        if self.action == "list":
            return serializers.AreaInfoSerializer
        else:
            return serializers.AreaSubsInfoSerializer

    def get_queryset(self):
        if self.action == "list":
            return Area.objects.filter(parent=None)
        else:
            return Area.objects.all()